package com.example.yls.demoa;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.ListView;
import android.widget.Toast;

import java.util.ArrayList;

public class MainActivity extends AppCompatActivity {
    private Button btnBroadcast;
    private  Button btnNetb;
    private Button btnTimeb;
      @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        btnBroadcast = findViewById(R.id.btn_myBroadcast);
        btnNetb = findViewById(R.id.btn_netB);
        btnTimeb = findViewById(R.id.btn_timeB);

        btnBroadcast.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
              Intent intent = new Intent();
              intent.setAction("MY_BROADCAST");
              intent.putExtra("info","Android BroadcastReceiver");
              sendBroadcast(intent);
            }
        });

          btnNetb.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View view) {
                  Intent intent = new Intent();
                  intent.setAction("android.net.conn.CONNECTIVITY_CHANGE");
                  intent.putExtra("info","网络");
                  sendBroadcast(intent);
              }
          });

          btnTimeb.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View view) {
                  Intent intent = new Intent();
                  intent.setAction("TIME_TICK_ACTION");
                  intent.putExtra("info","时间");
                  sendBroadcast(intent);
              }
          });

    }
}
